package test_gui01;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.BevelBorder;

import java.util.*;
import java.text.*;
import java.util.Timer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class TimeFrame extends JFrame //implements ActionListener
{
  JLabel label;
  SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
  
 
  
  public TimeFrame()
  {
   /* super( "Time Frame" );
    setSize( 500, 500 );
    label = new JLabel( sdf.format( new GregorianCalendar().getTime() ) );
    label.setHorizontalAlignment( JLabel.RIGHT );
    Container cont = getContentPane();
    cont.add( label, BorderLayout.SOUTH );
   */
   
	  Timer timer = new Timer(500, actionListener);
	  timer.start();

 
   
     /* 
    JLabel jLabel2 = new JLabel();
    jLabel2.setText("StatusBar:");

    JPanel contentPane = (JPanel)this.getContentPane();
    contentPane.setLayout(new BorderLayout(0, 0));
    contentPane.add(jLabel2, BorderLayout.SOUTH); 
    */
    JFrame frame = new JFrame();
    frame.setLayout(new BorderLayout());
    frame.setSize(500, 500);

    // create the status bar panel and shove it down the bottom of the frame
    JPanel statusPanel = new JPanel();
    statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    frame.add(statusPanel, BorderLayout.SOUTH);
    statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
    statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
    
    JLabel statusLabel = new JLabel(sdf.format( new GregorianCalendar().getTime() ));
    
    statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
    statusPanel.add(statusLabel);

    frame.setVisible(true);
    
    
    
  }
  
  public void actionPerformed( ActionEvent ae )
  {
    label.setText( sdf.format( new GregorianCalendar().getTime() ) );
  }
  
  
  ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("Hello World Timer");
        label.setText( sdf.format( new GregorianCalendar().getTime() ) );
      }
    };
  
  
  
  public static void main(String[] args) 
  {
    TimeFrame tf = new TimeFrame();
    

    
   // tf.setVisible( true );
  }
}



class ClockLabel extends JLabel implements ActionListener {
	  public ClockLabel( ) {
	    super("" + new Date( ));
	    Timer t = new Timer(1000, this);
	    t.start( );
	  }
	  public void actionPerformed(ActionEvent ae) {
	    setText((new Date( )).toString( ));
	  }
	}